<template>
	<view :class="{bg141414:theme}" style="min-height: 100vh;">
		<view class="con ">
			<back title="设置"></back>
			<view class="pg30 borderE1E1E1 ra20">
				<view @click="getupimg" class="flex-ju-b ">
					<view class="size26 color999 ">头像</view>
					<view class="flex-a-i">
						<image class="image wh70-70 ra70" :src="userinfo.headimg"></image>
						<image class="image width10 ml20" mode="widthFix" src="/static/right.png"></image>
					</view>
				</view>
				<view class="flex-ju-b mt50">
					<view class="size26 color999 ">昵称</view>
					<view class="flex-a-i size29 color999">
						<input type="text" maxlength="6" v-model="userinfo.name" placeholder="请输入名称"
							style="text-align: right;" @blur="savename">
						<image class="image width10 ml20" mode="widthFix" src="/static/right.png"></image>
					</view>
				</view>
				<view class="flex-ju-b mt50">
					<view class="size26 color999">绑定手机</view>
					<view class="flex-a-i size29 ">
						{{phone}}
					</view>
				</view>
				<view class="flex-ju-b mt50">
					<view class="size26 color999">区块链地址</view>
					<view v-if="userinfo.metaAddress" class="flex-a-i size29 color333">
						{{userinfo.metaAddress.substring(0,5)}}...
						<image class="image width20 ml20" @click="copy(userinfo.metaAddress)" mode="widthFix" src="/static/hcopy.png"></image>
					</view>
				</view>
			</view>
			
			
			
			<!-- <view class="flex-ju-b mt50">
			<view class="size35 bold">区块链地址</view>
			<view class="flex-a-i size29 color999">
				{{userInfo.metaAddress.substring(0,5)}}...
				<image class="image width20 ml20" mode="widthFix" src="/static/img/copy.png"></image>
			</view>
		</view>
		<view class="flex-ju-b mt50">
			<view class="size35 bold">区块链查询</view>
			<view class="flex-a-i size29 color999">
				<image class="image width10 ml20" mode="widthFix" src="/static/img/right.png"></image>
			</view>
		</view> -->
		
		<!-- <view  v-if="hidden!=1" @click="tapshiming" class="flex-ju-b mt50">
			<view class="size26 bold">实名验证</view>
			<view class="flex-a-i size29 color999">
				<image class="image width10 ml20" mode="widthFix" src="/static/img/right.png"></image>
			</view>
		</view> -->

			<!-- <view @click="tapzhuxiao" class="flex-ju-b mt50">
				<view class="size26 bold">注销账户</view>
				<view class="flex-a-i size29 color999">
					<image class="image width10 ml20" mode="widthFix" src="/static/img/right.png"></image>
				</view>
			</view> -->
			<!-- #ifdef APP -->
				<view class="flex-ju-b mt50">
					<view class="size26 bold">版本号</view>
					<view class="flex-a-i size29 color999">
						{{version?version:'1.0.0'}}
					</view>
				</view>
			<!-- #endif -->
				

			<view class="pg30 borderE1E1E1 ra20 mt30">
				<view @click="navto('password?type=level2password')" class="flex-ju-b mt20">
					<view class="size26 color999">交易密码</view>
					<view class="flex-a-i size29 color999">
						<image class="image width10 ml20" mode="widthFix" src="/static/right.png"></image>
					</view>
				</view>
				<view @click="navto('password?type=password')" class="flex-ju-b mt50">
					<view class="size26 color999">登录密码</view>
					<view class="flex-a-i size29 color999">
						<image class="image width10 ml20" mode="widthFix" src="/static/right.png"></image>
					</view>
				</view>
			</view>
			<view class="pg30 borderE1E1E1 ra20 mt30">
				<view @click="navto('about')" class="flex-ju-b ">
					<view class="size26 color999">关于我们</view>
					<view class="flex-a-i size29 color999">
						<image class="image width10 ml20" mode="widthFix" src="/static/right.png"></image>
					</view>
				</view>
			</view>
			

		</view>
		<view class="posifi  bottom20 zindex10 width1000 hidden ra20"
			>
				<view @click="taplogin" class="srgb con height100 size29  border000 flex-ju-c ra20 bold" :class="theme?'color000':''">
					退出登录
				</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				version:uni.getStorageSync('version'),
				idcardFlag:"",
				theme: uni.getStorageSync('theme'),
				userinfo: {},
				phone: uni.getStorageSync('phone')
			}
		},
		onLoad() {
			this.userinfo = uni.getStorageSync('user')
			
		if (uni.getStorageSync('isOkData')) {
				this.idcardFlag = uni.getStorageSync('isOkData').is_ok
			}
		},
		methods: {
			tapshiming(){
				if(this.idcardFlag){
					this.navto('shiming/detail')
				}else{
					this.navto('shiming/index')
				}
			},
			tapzhuxiao() {
				uni.showModal({
					title: '提示',
					content: '是否注销账号！',
					success: (res) => {
						if (res.confirm) {
							this.http('user/batalan', {}, 'post').then(res => {
								uni.showToast({
									title: "注销成功",
									icon: "none"
								})
								uni.reLaunch({
									url: "/pages/login"
								})
								uni.removeStorageSync('token')
							})
						}
					}
				});
			},
			taplogin() {
				uni.reLaunch({
					url: "/pages/login"
				})
				uni.removeStorageSync('token')
			},
			savename() {
				if (!this.userinfo.name) {
					uni.showToast({
						title: "请输入名字",
						icon: "none"
					})
					return
				}
				this.http('user/name', {
					name: this.userinfo.name
				}, 'post').then(res => {
					uni.showToast({
						title: "修改成功",
						icon: "none"
					})
					setTimeout(() => {
						this.getUserInfo()
					}, 700)
				})
			},
			getUserInfo() {
				this.http('userInfo').then((res) => {
					this.userinfo = res.data
					uni.setStorageSync('user', res.data)
				})
			},
			getupimg() {
				uni.chooseImage({
					count: 1,
					success: (res) => {
						uni.showLoading({
							mask: true
						}) 
					
						uni.uploadFile({
								url: uni.getStorageSync('upimg') + 'user/headimg',
								filePath: res.tempFilePaths[0],
								name: 'file',
									header: {
										Authorization: uni.getStorageSync('token')
									},
								success: (uploadRes) => {
								  		uni.showToast({
								  			title: "修改成功",
								  			icon: "none"
								  		})
								  		setTimeout(() => {
								  			this.getUserInfo()
								  		}, 700)
								  		uni.hideLoading()
								  
								},
								fail: (err) => {
								 		uni.hideLoading()
								 		uni.showModal({
								 			content: "网络错误,稍后再试"
								 		})
								}
						});
					 
					}, 
					fail:(res)=> {
						console.log(22222)
						console.log(res)
					}
				})

			}
		}
	}
</script>

<style>

</style>